﻿using System;
namespace Kis.Xroad.Eu {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="XsdMinOccursMaxOccursUDFS", Namespace="http://kis.x-road.eu/", Target=typeof(XsdMinOccursMaxOccursUDFS))]
    public class XsdMinOccursMaxOccursUDFSSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected XsdMinOccursMaxOccursUDFS clazz;
        
        public XsdMinOccursMaxOccursUDFSSerializer(XsdMinOccursMaxOccursUDFS clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.Min0Maz1NonNil!=null) {
                Writer.WriteStartElement("Min0_Maz_1_NonNil");
                Writer.WriteString(clazz.Min0Maz1NonNil.ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Min0Maz1Nil!=null) {
                Writer.WriteStartElement("Min0_Maz_1_Nil");
                Writer.WriteString(clazz.Min0Maz1Nil.ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("Min1_Maz_1_NonNil");
            if (clazz.Min1Maz1NonNil!=null) {
                Writer.WriteString(clazz.Min1Maz1NonNil.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Min1Maz1NonNil");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Min1_Maz_1_Nil");
            if (clazz.Min1Maz1Nil!=null) {
                Writer.WriteString(clazz.Min1Maz1Nil.ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="Min0_Maz_1_NonNil") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>XsdMinOccursMaxOccursUDFS>Min0_Maz_1_NonNil");
                }
                clazz.Min0Maz1NonNil = new global::Kis.Xroad.Eu.PositiveCelcius(Reader.ReadElementString("Min0_Maz_1_NonNil"));
            }
            if (Reader.LocalName=="Min0_Maz_1_Nil") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Min0Maz1Nil = new global::Kis.Xroad.Eu.PositiveCelcius(Reader.ReadElementString("Min0_Maz_1_Nil"));
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Min1_Maz_1_NonNil") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>XsdMinOccursMaxOccursUDFS>Min1_Maz_1_NonNil");
                }
                clazz.Min1Maz1NonNil = new global::Kis.Xroad.Eu.PositiveCelcius(Reader.ReadElementString("Min1_Maz_1_NonNil"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>XsdMinOccursMaxOccursUDFS>Min1_Maz_1_NonNil", Reader.LocalName);
            }
            if (Reader.LocalName=="Min1_Maz_1_Nil") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Min1Maz1Nil = new global::Kis.Xroad.Eu.PositiveCelcius(Reader.ReadElementString("Min1_Maz_1_Nil"));
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>XsdMinOccursMaxOccursUDFS>Min1_Maz_1_Nil", Reader.LocalName);
            }
        }
    }
}
